Skip to content

HTML API: Preserve PRE/LISTING newline skipping after seek#58

Open
sirreal wants to merge 1 commit into
trunkfrom
fix-pre-seek
Open

HTML API: Preserve PRE/LISTING newline skipping after seek#58
sirreal wants to merge 1 commit into
trunkfrom
fix-pre-seek

Conversation

@sirreal

@sirreal sirreal commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes WP_HTML_Tag_Processor::seek() when returning to a bookmark set on a text node that suppresses the first LF after <pre> or <listing>.

Before this change, the first scan of <pre>\n \n\n><pre> returned " \n\n>", but seeking back to a bookmark on that same text token returned "\n \n\n>". The bookmark stored the token span, but not the parser state that says the leading newline should be skipped.

This change:

  • records when a bookmark is set on a text token with an active PRE/LISTING skipped newline;
  • restores that skipped-newline state during seek() before reparsing the bookmarked token;
  • keeps skip_newline_at aligned when pending lexical updates shift token offsets;
  • preserves bookmark behavior for exact-start replacements, zero-length insertions, non-empty insertions at the skipped text start, and no-op insertions.

Testing

  • WP_TESTS_SKIP_INSTALL=1 ./vendor/bin/phpunit --group html-api,html-api-html5lib-tests
  • ./vendor/bin/phpcs --standard=phpcs.xml.dist src/wp-includes/html-api/class-wp-html-tag-processor.php tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php
  • php -l on changed PHP files
  • git diff --check

Trac ticket: TBD

Use of AI Tools

AI assistance: Yes
Tool(s): Codex
Model(s): GPT-5
Used for: diagnosing the seek replay bug, implementing and iterating on tests, running adversarial review passes, and drafting this PR description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@sirreal sirreal changed the title HTML API: Preserve PRE/LISTING text replay after seek HTML API: Preserve PRE/LISTING newline skipping after seek Jun 12, 2026
@sirreal sirreal marked this pull request as ready for review June 12, 2026 20:45
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant